```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>EXPLAIN SQL执行计划详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
            line-height: 1.6;
        }
        .container {
            max-width: 1200px;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
            color: #1e293b;
        }
        .hero {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
            color: white;
        }
        .sql-code {
            background-color: #1e293b;
            color: #e2e8f0;
            border-radius: 0.5rem;
            font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .type-indicator {
            position: relative;
            padding-left: 1.75rem;
        }
        .type-indicator:before {
            content: "";
            position: absolute;
            left: 0;
            top: 0.5rem;
            width: 1rem;
            height: 1rem;
            border-radius: 50%;
        }
        .tooltip-icon {
            cursor: pointer;
            color: #64748b;
            transition: color 0.2s;
        }
        .tooltip-icon:hover {
            color: #4f46e5;
        }
        .section-anchor {
            scroll-margin-top: 100px;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero py-20 px-6 rounded-b-3xl shadow-xl">
        <div class="container mx-auto text-center">
            <div class="inline-block bg-white bg-opacity-20 px-4 py-2 rounded-full mb-6">
                <span class="text-sm font-semibold tracking-wider">SQL优化指南</span>
            </div>
            <h1 class="text-4xl md:text-6xl font-bold mb-6">深入理解<span class="text-yellow-300">EXPLAIN</span>执行计划</h1>
            <p class="text-xl md:text-2xl max-w-3xl mx-auto opacity-90 mb-10">剖析MySQL查询优化的核心工具，掌握SQL性能调优的关键技能</p>
            <div class="flex flex-wrap justify-center gap-4">
                <a href="#introduction" class="px-8 py-3 bg-white text-indigo-700 font-semibold rounded-full hover:bg-opacity-90 transition">开始探索</a>
                <a href="#visual-guide" class="px-8 py-3 border-2 border-white text-white font-semibold rounded-full hover:bg-white hover:bg-opacity-10 transition">可视化指南</a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-16">
        <!-- Introduction Section -->
        <section id="introduction" class="mb-20 section-anchor">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-gradient-to-r from-indigo-500 to-purple-600 flex-grow"></div>
                <h2 class="text-3xl font-bold px-4">EXPLAIN命令简介</h2>
                <div class="h-1 bg-gradient-to-r from-purple-600 to-indigo-500 flex-grow"></div>
            </div>
            
            <div class="bg-white rounded-xl shadow-lg p-8 mb-8">
                <p class="text-lg mb-6">EXPLAIN 命令是查看查询优化器如何决定执行查询的主要方法。使用EXPLAIN时，只需要在查询中的SELECT关键字之前增加EXPLAIN这个词即可。</p>
                <p class="text-lg mb-6">MySQL会在查询上设置一个标记，当执行查询时，这个标记会使其返回关于在执行计划中每一步的信息，而不是执行它。它会返回一行或多行信息，显示出执行计划中的每一部分和执行的次序。</p>
                <p class="text-lg font-medium text-indigo-700">通过分析EXPLAIN结果，我们可以找到查询语句或是表结构的性能瓶颈。</p>
            </div>
            
            <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1651407800658-099a3f51-7a6b-4afc-a98b-e72c34adc425.png" alt="EXPLAIN执行计划示例" class="w-full rounded-xl shadow-lg border border-gray-200">
        </section>

        <!-- Key Features Section -->
        <section id="key-features" class="mb-20 section-anchor">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-gradient-to-r from-indigo-500 to-purple-600 flex-grow"></div>
                <h2 class="text-3xl font-bold px-4">EXPLAIN能做什么</h2>
                <div class="h-1 bg-gradient-to-r from-purple-600 to-indigo-500 flex-grow"></div>
            </div>
            
            <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
                <div class="card bg-white p-6 rounded-xl shadow-md border-l-4 border-indigo-500">
                    <div class="text-indigo-600 text-2xl mb-4">
                        <i class="fas fa-list-ol"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">分析表的读取顺序</h3>
                    <p class="text-gray-600">了解MySQL如何决定多表查询时的连接顺序</p>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-md border-l-4 border-purple-500">
                    <div class="text-purple-600 text-2xl mb-4">
                        <i class="fas fa-search"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">识别操作类型</h3>
                    <p class="text-gray-600">判断查询使用的是全表扫描、索引扫描还是范围扫描</p>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-md border-l-4 border-blue-500">
                    <div class="text-blue-600 text-2xl mb-4">
                        <i class="fas fa-key"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">索引使用情况</h3>
                    <p class="text-gray-600">明确哪些索引可用以及哪些索引被实际使用</p>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-md border-l-4 border-green-500">
                    <div class="text-green-600 text-2xl mb-4">
                        <i class="fas fa-link"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">表间引用关系</h3>
                    <p class="text-gray-600">了解多表查询中的连接条件和引用关系</p>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-md border-l-4 border-yellow-500">
                    <div class="text-yellow-600 text-2xl mb-4">
                        <i class="fas fa-filter"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">行数估算</h3>
                    <p class="text-gray-600">获取优化器对每张表需要检查行数的估算值</p>
                </div>
                
                <div class="card bg-white p-6 rounded-xl shadow-md border-l-4 border-red-500">
                    <div class="text-red-600 text-2xl mb-4">
                        <i class="fas fa-chart-line"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">性能瓶颈识别</h3>
                    <p class="text-gray-600">发现查询中的潜在性能问题，如全表扫描或临时表使用</p>
                </div>
            </div>
        </section>

        <!-- Parameter Details Section -->
        <section id="parameter-details" class="mb-20 section-anchor">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-gradient-to-r from-indigo-500 to-purple-600 flex-grow"></div>
                <h2 class="text-3xl font-bold px-4">EXPLAIN结果参数详解</h2>
                <div class="h-1 bg-gradient-to-r from-purple-600 to-indigo-500 flex-grow"></div>
            </div>
            
            <!-- ID Parameter -->
            <div class="bg-white rounded-xl shadow-lg overflow-hidden mb-10">
                <div class="bg-gradient-to-r from-indigo-600 to-purple-600 px-6 py-4 text-white">
                    <h3 class="text-xl font-bold">ID - 查询执行顺序</h3>
                </div>
                <div class="p-6">
                    <p class="mb-4">代表执行select子句或操作表的顺序：</p>
                    <ul class="list-disc pl-6 mb-6 space-y-2">
                        <li><span class="font-semibold">id越大，越先执行</span> - 子查询通常会有更大的id值</li>
                        <li><span class="font-semibold">id相同，执行顺序由上至下</span></li>
                        <li><span class="font-semibold">id相同和不同同时存在</span> - 优先级高的优先执行，优先级相同的按照由上至下的顺序执行</li>
                    </ul>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div>
                            <div class="flex items-center mb-2">
                                <span class="font-mono bg-gray-100 px-2 py-1 rounded text-sm mr-2">示例SQL</span>
                            </div>
                            <div class="sql-code p-4 rounded-lg mb-4">
                                <code>EXPLAIN<br>select * from t_user u1 where u1.id =(<br>select u.id from t_user u where u.id = 2)</code>
                            </div>
                            <div class="text-sm text-gray-600">
                                <i class="fas fa-info-circle mr-1"></i> id较大的子查询先执行
                            </div>
                        </div>
                        <div>
                            <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1651407800959-dc27954c-14a6-4f22-9ca4-9cd0896a72a0.png" alt="ID参数示例" class="w-full rounded border border-gray-200">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- select_type Parameter -->
            <div class="bg-white rounded-xl shadow-lg overflow-hidden mb-10">
                <div class="bg-gradient-to-r from-indigo-600 to-purple-600 px-6 py-4 text-white">
                    <h3 class="text-xl font-bold">select_type - 查询类型</h3>
                </div>
                <div class="p-6">
                    <p class="mb-4">主要用于区别普通查询、联合查询、子查询等复杂查询：</p>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div>
                            <ul class="space-y-3">
                                <li class="type-indicator">
                                    <span class="font-semibold">SIMPLE</span> - 简单的select查询，不包含子查询或UNION
                                </li>
                                <li class="type-indicator">
                                    <span class="font-semibold">PRIMARY</span> - 复杂查询中最外层的SELECT
                                </li>
                                <li class="type-indicator">
                                    <span class="font-semibold">SUBQUERY</span> - SELECT或WHERE中的子查询
                                </li>
                                <li class="type-indicator">
                                    <span class="font-semibold">DERIVED</span> - FROM中的子查询，结果存放在临时表中
                                </li>
                                <li class="type-indicator">
                                    <span class="font-semibold">UNION</span> - UNION中第二个及以后的SELECT
                                </li>
                                <li class="type-indicator">
                                    <span class="font-semibold">UNION RESULT</span> - UNION查询的结果集
                                </li>
                            </ul>
                        </div>
                        <div>
                            <div class="sql-code p-4 rounded-lg mb-4">
                                <code>-- DERIVED示例<br>EXPLAIN<br>select * from t_user u1,(select * from t_user u2) u3</code>
                            </div>
                            <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1661390292295-93ce3bab-d687-4780-8fdd-0e996bfff9fa.png" alt="select_type示例" class="w-full rounded border border-gray-200">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- type Parameter -->
            <div class="bg-white rounded-xl shadow-lg overflow-hidden mb-10">
                <div class="bg-gradient-to-r from-indigo-600 to-purple-600 px-6 py-4 text-white">
                    <h3 class="text-xl font-bold">type - 访问类型</h3>
                </div>
                <div class="p-6">
                    <p class="mb-4">查询类型从最好到最差依次是：<br><span class="font-bold">system > const > eq_ref > ref > range > index > All</span></p>
                    <p class="mb-6 text-gray-600">一般情况下，至少要保证达到index级别，最好能达到ref级别。</p>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div>
                            <div class="space-y-4">
                                <div>
                                    <h4 class="font-semibold mb-2">const <span class="text-sm font-normal text-green-600">(最优级别之一)</span></h4>
                                    <p class="text-sm">通过索引一次就找到，用于比较PRIMARY KEY或UNIQUE索引</p>
                                    <div class="sql-code p-3 rounded-lg mt-2 text-sm">
                                        <code>EXPLAIN<br>select empno from emp where empno = 7369;</code>
                                    </div>
                                </div>
                                
                                <div>
                                    <h4 class="font-semibold mb-2">eq_ref <span class="text-sm font-normal text-green-500">(高性能)</span></h4>
                                    <p class="text-sm">唯一性索引扫描，每个索引键只匹配一行数据</p>
                                    <div class="sql-code p-3 rounded-lg mt-2 text-sm">
                                        <code>EXPLAIN<br>select ename,sal from emp where ename = 'ALLEN';</code>
                                    </div>
                                </div>
                                
                                <div>
                                    <h4 class="font-semibold mb-2">ref <span class="text-sm font-normal text-blue-500">(良好)</span></h4>
                                    <p class="text-sm">非唯一性索引扫描，返回匹配某个单独值的行</p>
                                    <div class="sql-code p-3 rounded-lg mt-2 text-sm">
                                        <code>EXPLAIN<br>select * from emp where job = 'SALESMAN';</code>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div>
                            <div class="space-y-4">
                                <div>
                                    <h4 class="font-semibold mb-2">range <span class="text-sm font-normal text-yellow-600">(一般)</span></h4>
                                    <p class="text-sm">只检索给定范围的行，使用索引选择行</p>
                                    <div class="sql-code p-3 rounded-lg mt-2 text-sm">
                                        <code>EXPLAIN<br>select ename from emp where ename like 'al%';</code>
                                    </div>
                                </div>
                                
                                <div>
                                    <h4 class="font-semibold mb-2">index <span class="text-sm font-normal text-orange-500">(较差)</span></h4>
                                    <p class="text-sm">扫描所有索引，比All快因为索引文件通常比数据文件小</p>
                                    <div class="sql-code p-3 rounded-lg mt-2 text-sm">
                                        <code>EXPLAIN<br>select empno from emp;</code>
                                    </div>
                                </div>
                                
                                <div>
                                    <h4 class="font-semibold mb-2">ALL <span class="text-sm font-normal text-red-500">(最差)</span></h4>
                                    <p class="text-sm">全表扫描，是最差的一种查询类型</p>
                                    <div class="sql-code p-3 rounded-lg mt-2 text-sm">
                                        <code>EXPLAIN<br>select * from emp;</code>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Other Parameters -->
            <div class="grid md:grid-cols-2 gap-6 mb-10">
                <!-- Possible Keys & Keys -->
                <div class="bg-white rounded-xl shadow-lg overflow-hidden">
                    <div class="bg-indigo-600 px-6 py-4 text-white">
                        <h3 class="text-lg font-bold">possible_keys & key</h3>
                    </div>
                    <div class="p-6">
                        <p class="mb-4"><span class="font-semibold">possible_keys:</span> 显示可能应用在这张表中的索引</p>
                        <p class="mb-4"><span class="font-semibold">key:</span> 实际使用的索引，如果为NULL则没有使用索引</p>
                        <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1651407802204-e46d7ff8-14ba-4531-8302-9648c08ce6ad.png" alt="keys示例" class="w-full rounded border border-gray-200">
                        <div class="mt-4 text-sm text-red-600">
                            <i class="fas fa-exclamation-triangle mr-1"></i> 当possible_keys有值而key为NULL时，表示索引未被实际使用
                        </div>
                    </div>
                </div>
                
                <!-- Rows & Extra -->
                <div class="bg-white rounded-xl shadow-lg overflow-hidden">
                    <div class="bg-purple-600 px-6 py-4 text-white">
                        <h3 class="text-lg font-bold">rows & Extra</h3>
                    </div>
                    <div class="p-6">
                        <p class="mb-4"><span class="font-semibold">rows:</span> 估算需要检查的行数，值越小越好</p>
                        <p class="mb-4"><span class="font-semibold">Extra:</span> 额外重要信息，特别注意以下性能损耗情况：</p>
                        <ul class="list-disc pl-6 space-y-1 text-sm">
                            <li><span class="font-semibold">Using filesort</span> - 需要额外的排序操作</li>
                            <li><span class="font-semibold">Using temporary</span> - 需要创建临时表</li>
                            <li><span class="font-semibold">Using index</span> - 覆盖索引，性能良好</li>
                            <li><span class="font-semibold">Using where</span> - 使用了WHERE过滤条件</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visual Guide Section -->
        <section id="visual-guide" class="mb-20 section-anchor">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-gradient-to-r from-indigo-500 to-purple-600 flex-grow"></div>
                <h2 class="text-3xl font-bold px-4">EXPLAIN执行计划可视化指南</h2>
                <div class="h-1 bg-gradient-to-r from-purple-600 to-indigo-500 flex-grow"></div>
            </div>
            
            <div class="bg-white rounded-xl shadow-lg p-8">
                <div class="mermaid">
                    graph TD
                    A[执行EXPLAIN命令] --> B[分析ID确定执行顺序]
                    B --> C[检查select_type了解查询类型]
                    C --> D[评估type访问类型质量]
                    D --> E[查看possible_keys和key确认索引使用]
                    E --> F[分析rows评估查询规模]
                    F --> G[检查Extra获取额外信息]
                    G --> H[综合评估查询性能]
                    H --> I[优化建议]
                    
                    classDef green fill:#dcfce7,stroke:#16a34a;
                    classDef yellow fill:#fef08a,stroke:#ca8a04;
                    classDef red fill:#fee2e2,stroke:#dc2626;
                    
                    class B,C,D,E,F,G,H,I green;
                </div>
                
                <div class="mt-8 grid md:grid-cols-3 gap-6">
                    <div class="bg-green-50 p-4 rounded-lg border border-green-200">
                        <h3 class="font-bold text-green-800 mb-2">良好性能指标</h3>
                        <ul class="text-sm space-y-1">
                            <li><i class="fas fa-check text-green-500 mr-1"></i> const/eq_ref访问类型</li>
                            <li><i class="fas fa-check text-green-500 mr-1"></i> 实际使用了索引(key不为NULL)</li>
                            <li><i class="fas fa-check text-green-500 mr-1"></i> rows值较小</li>
                            <li><i class="fas fa-check text-green-500 mr-1"></i> Extra显示Using index</li>
                        </ul>
                    </div>
                    
                    <div class="bg-yellow-50 p-4 rounded-lg border border-yellow-200">
                        <h3 class="font-bold text-yellow-800 mb-2">警告信号</h3>
                        <ul class="text-sm space-y-1">
                            <li><i class="fas fa-exclamation-triangle text-yellow-500 mr-1"></i> range/index访问类型</li>
                            <li><i class="fas fa-exclamation-triangle text-yellow-500 mr-1"></i> possible_keys有值但key为NULL</li>
                            <li><i class="fas fa-exclamation-triangle text-yellow-500 mr-1"></i> rows值较大</li>
                        </ul>
                    </div>
                    
                    <div class="bg-red-50 p-4 rounded-lg border border-red-200">
                        <h3 class="font-bold text-red-800 mb-2">严重问题</h3>
                        <ul class="text-sm space-y-1">
                            <li><i class="fas fa-times text-red-500 mr-1"></i> ALL全表扫描</li>
                            <li><i class="fas fa-times text-red-500 mr-1"></i> Extra显示Using filesort/temporary</li>
                            <li><i class="fas fa-times text-red-500 mr-1"></i> 缺少适当的索引</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary Section -->
        <section id="summary" class="mb-10 section-anchor">
            <div class="bg-indigo-50 rounded-xl p-8 border border-indigo-200">
                <h2 class="text-2xl font-bold text-indigo-800 mb-4">EXPLAIN分析要点总结</h2>
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h3 class="font-semibold text-lg mb-3 text-indigo-700">关键指标关注顺序</h3>
                        <ol class="list-decimal pl-6 space-y-2">
                            <li><span class="font-medium">type</span> - 访问类型，判断是否走索引</li>
                            <li><span class="font-medium">key</span> - 实际使用的索引，确认是否使用了最佳索引</li>
                            <li><span class="font-medium">rows</span> - 扫描行数估算，评估查询规模</li>
                            <li><span class="font-medium">Extra</span> - 特别注意性能损耗情况</li>
                        </ol>
                    </div>
                    <div>
                        <h3 class="font-semibold text-lg mb-3 text-indigo-700">常见优化方向</h3>
                        <ul class="list-disc pl-6 space-y-2">
                            <li>为WHERE条件、JOIN条件和ORDER BY列添加适当索引</li>
                            <li>避免SELECT *，只查询必要字段</li>
                            <li>重写复杂子查询为JOIN操作</li>
                            <li>使用EXPLAIN ANALYZE获取实际执行数据</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```